{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ec7c2a6e",
   "metadata": {},
   "source": [
    "# 金融市场基第4课书面作业\n",
    "学号：114847\n",
    "\n",
    "**作业内容：**  \n",
    "1. 一年期的贴现债券现价为960美金，3个月期无风险年利率为5%，则3个月期的该债券远期合约交割价格应该为多少？  \n",
    "2. 一份标的证券为一年期限的贴现债券、剩余期限为6个月的远期合约多头，交割价格为960美金，6个月期的无风险利率为6%（连续复利），该债券现价为940美元，则该远期合约多头价值为多少？\n",
    "3. 一个交易商购买了一份小麦的期货合约（标的资产是5000布什尔的小麦），购买时小麦的即时价格为3.05美金/布什尔，合约初始保证金为4500美金，维持保证金要求3750美金，当小麦价格为多少时，这个交易商会收到交易所催缴保证金的电话？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68740b23",
   "metadata": {},
   "source": [
    "## 第1题\n",
    "一年期的贴现债券现价为960美金，3个月期无风险年利率为5%，则3个月期的该债券远期合约交割价格应该为多少？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6488d358",
   "metadata": {},
   "source": [
    "答：  \n",
    "根据公式：  \n",
    "$$\n",
    "K = S_0 e^{rt}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2bc66504",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3个月期的该债券远期合约交割价格=$972.075313\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "S0=960\n",
    "r = 0.05\n",
    "t = 3./12.\n",
    "K = S0*np.exp(r*t)\n",
    "print('3个月期的该债券远期合约交割价格=$%f'%(K))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2ff9810",
   "metadata": {},
   "source": [
    "## 第2题\n",
    "一份标的证券为一年期限的贴现债券、剩余期限为6个月的远期合约多头，交割价格为960美金，6个月期的无风险利率为6%（连续复利），该债券现价为940美元，则该远期合约多头价值为多少？"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e54d580d",
   "metadata": {},
   "source": [
    "根据公式：\n",
    "$$\n",
    "f = (F_0-K)e^{-rT}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "51e1f13f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "该远期合约多头价值为:$ -19.40891067097016\n"
     ]
    }
   ],
   "source": [
    "F0 = 940\n",
    "K = 960\n",
    "r = 0.06\n",
    "T = 6./12.\n",
    "f = (F0-K)*np.exp(-1*r*T)\n",
    "print('该远期合约多头价值为:$',f)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74b5625b",
   "metadata": {},
   "source": [
    "## 第3题\n",
    "一个交易商购买了一份小麦的期货合约（标的资产是5000布什尔的小麦），购买时小麦的即时价格为3.05美金/布什尔，合约初始保证金为4500美金，维持保证金要求3750美金，当小麦价格为多少时，这个交易商会收到交易所催缴保证金的电话？\n",
    "\n",
    "$$\n",
    "初始保证金 = 5000\\times p_0\\times ratio_{inital}=4500 \\\\\n",
    "ratio_{inital} = \\frac{4500}{5000\\times p_0}\n",
    "$$\n",
    "\n",
    "上式中$p_0$表示购买小麦时的价格。$ratio_{initial}$表示初始保证金比例。\n",
    "\n",
    "如果小麦价格下跌$p_x$时，本期货合约的总价值乘以保证金比例小于3750时，交易所就要催缴保证金，此时：\n",
    "$$\n",
    "5000\\times 𝑝_x\\times 𝑟𝑎𝑡𝑖𝑜_{𝑖𝑛𝑖𝑡𝑎𝑙} \\le 3750 \\\\\n",
    "5000\\times 𝑝_x\\times \\frac{4500}{5000\\times p_0} \\le 3750 \\\\\n",
    "p_x \\le \\frac{3750 \\times p_0}{4500}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0bb784bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当小麦价格为$2.541667时，这个交易商会收到交易所催缴保证金的电话。\n"
     ]
    }
   ],
   "source": [
    "p0=3.05\n",
    "px = 3750*p0/4500\n",
    "print('当小麦价格为$%f时，这个交易商会收到交易所催缴保证金的电话。'%(px))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2bad9c1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
